//
//  ReceiptViewController.m
//  联付商圈
//
//  Created by apple on 17/7/19.
//  Copyright © 2017年 lianfu. All rights reserved.
//

#define HEIGHT 280
#import "ReceiptViewController.h"
#import "ReceiptCollectionViewCell.h"
#import "ReceiptTableViewCell.h"
#import "PayViewController.h"

@interface ReceiptViewController ()<UICollectionViewDelegate, UICollectionViewDataSource>
@property (nonatomic, strong) UIImageView *QRImageView;
@property (nonatomic, strong) NSArray *payArr;
@property (nonatomic, strong) NSArray *payImgArr;

@end

@implementation ReceiptViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self changeNavigationController];
    [self buildMainInterface];
}

- (void)changeNavigationController
{
    self.navigationController.navigationBar.hidden = NO;
    self.navigationController.interactivePopGestureRecognizer.enabled = NO;
    self.navigationItem.title = @"店铺收银台";
}

- (void)buildMainInterface
{
    self.view.backgroundColor = [UIColor colorWithRed:0.96 green:0.96 blue:0.96 alpha:1.00];
    self.payArr = @[@"微信支付", @"支付宝"];
    
    self.payImgArr = [NSArray arrayWithObjects:@"微信@2x", @"支付宝@2x", nil];
    
    UIView *backView = [[UIView alloc] init];
    backView.backgroundColor = [UIColor whiteColor];
    backView.layer.cornerRadius = 10;
    [self.view addSubview:backView];
    [backView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_offset(UIEdgeInsetsMake(74, 10, 69, 10));
    }];
    
    UIView *topView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREENW - 20, (SCREENH - 143) / 5 * 3)];
    UIBezierPath *topMaskPath = [UIBezierPath bezierPathWithRoundedRect:topView.bounds byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(10,10)];
    CAShapeLayer *topMaskLayer = [[CAShapeLayer alloc] init];
    topMaskLayer.frame = topView.bounds;
    topMaskLayer.path = topMaskPath.CGPath;
    topView.layer.mask = topMaskLayer;
    topView.backgroundColor = [UIColor colorWithRed:0.00 green:0.56 blue:0.83 alpha:1.00];
    [backView addSubview:topView];
    
    
    UILabel *titleLabel = [[UILabel alloc] init];
    titleLabel.textColor = [UIColor whiteColor];
    titleLabel.textAlignment = 1;
    titleLabel.font = [UIFont systemFontOfSize:30 * FONTSIZE];
    titleLabel.text = @"扫我付款";
    [topView addSubview:titleLabel];
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(topView.mas_left).offset(0);
        make.right.equalTo(topView.mas_right).offset(0);
        make.top.equalTo(topView.mas_top).offset(20);
        make.height.mas_equalTo(30);
    }];
    
    UIView *QRView = [[UIView alloc] init];
    QRView.backgroundColor = [UIColor whiteColor];
    QRView.layer.cornerRadius = 5;
    [topView addSubview:QRView];
    [QRView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_offset(UIEdgeInsetsMake(70, 70, 40, 70));
    }];
    
    UILabel *tipLabel = [[UILabel alloc] init];
    tipLabel.textColor = [UIColor colorWithRed:0.53 green:0.52 blue:0.55 alpha:1.00];
    tipLabel.text = @"支持任意扫一扫,向我付款";
    tipLabel.textAlignment = 1;
    tipLabel.font = [UIFont systemFontOfSize:15 *  FONTSIZE];
    [QRView addSubview:tipLabel];
    [tipLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(QRView.mas_left).offset(0);
        make.right.equalTo(QRView.mas_right).offset(0);
        make.bottom.equalTo(QRView.mas_bottom).offset(-10);
        make.height.mas_equalTo(20);
    }];
    
//    self.QRImageView = [[UIImageView alloc] init];
//    self.QRImageView.image = [UIImage imageNamed:@"QRImageView"];
//    [topView addSubview:_QRImageView];
//    [self.QRImageView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.equalTo(QRView.mas_left).offset(30);
//        make.right.equalTo(QRView.mas_right).offset(-30);
//        make.top.equalTo(QRView.mas_top).offset(10);
//        make.bottom.equalTo(tipLabel.mas_top).offset(-10);
//    }];
    
    UIView *bottomView = [[UIView alloc] initWithFrame:CGRectMake(0, topView.frame.size.height, topView.frame.size.width, (SCREENH - 143) / 5 * 2)];
    UIBezierPath *bottomMaskPath = [UIBezierPath bezierPathWithRoundedRect:bottomView.bounds byRoundingCorners:UIRectCornerBottomLeft | UIRectCornerBottomRight cornerRadii:CGSizeMake(10,10)];
    CAShapeLayer *bottomMaskLayer = [[CAShapeLayer alloc] init];
    bottomMaskLayer.frame = bottomView.bounds;
    bottomMaskLayer.path = bottomMaskPath.CGPath;
    bottomView.layer.mask = bottomMaskLayer;
    bottomView.backgroundColor = [UIColor whiteColor];
    [backView addSubview:bottomView];
    
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    layout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
    layout.minimumLineSpacing = 0;
    layout.minimumInteritemSpacing = 0;
    layout.itemSize = CGSizeMake(bottomView.frame.size.width / 5, bottomView.frame.size.width / 5 + 10);
    
    UICollectionView *collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(bottomView.frame.size.width / 5*1.5, 0, bottomView.frame.size.width, bottomView.frame.size.width / 5 + 10) collectionViewLayout:layout];
    collectionView.backgroundColor = [UIColor whiteColor];
    collectionView.delegate = self;
    collectionView.dataSource = self;
    [bottomView addSubview:collectionView];
    [collectionView registerClass:[ReceiptCollectionViewCell class] forCellWithReuseIdentifier:@"payCell"];
    
    UIImageView *payImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"信用卡"]];
    [bottomView addSubview:payImageView];
    [payImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_offset(UIEdgeInsetsMake(collectionView.frame.size.height, 0, 0, 0));
    }];
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return _payImgArr.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    ReceiptCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"payCell" forIndexPath:indexPath];
    cell.titleLabel.text = [_payArr objectAtIndex:indexPath.row];
    cell.imgView.image = [UIImage imageNamed:[NSString stringWithFormat:@"%@", [_payImgArr objectAtIndex:indexPath.row]]];
    return cell;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
